package com.jxc.dao.impl;

import java.sql.SQLException;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.jxc.dao.InquiryListDao;
import com.jxc.entity.Inquirylist;
import com.jxc.util.PageBean;

public class InquiryListDaoImpl extends HibernateDaoSupport implements
		InquiryListDao {

	public void save(Inquirylist inquiryList) {
		this.getHibernateTemplate().save(inquiryList);
	}

	public Inquirylist getInquiry(Inquirylist inquirylist) {

		return  (Inquirylist)this.getHibernateTemplate().get(Inquirylist.class, inquirylist.getId());
	}

	public void updateInquiryList(Inquirylist inquirylist) {
		
		this.getHibernateTemplate().update(inquirylist);
	}

	public PageBean findInquiryList(final String hql,final PageBean pb) {
		 this.getHibernateTemplate().execute(new HibernateCallback() {
			public Object doInHibernate(Session session) throws HibernateException,
					SQLException {
				Query query=session.createQuery(hql);
				pb.setTotalitem(query.list().size());
				query.setFirstResult((pb.getPageon()-1)*pb.getPageon());
				query.setMaxResults(pb.getPagesize());
				pb.getTotalpage();
				pb.setList(query.list());
				
				return pb;
			}
		});
		return pb;
	}
}
